﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLTV.Public;

namespace QLTV.DAL
{
    public class QuyDinhDAL
    {
        ConnectionData connect;
        public DataTable QuyDinh_LoadDuLieu()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("QuyDinh_LoadDuLieu");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int QuyDinh_UPDATE(QuyDinhDTO qdDTO)
        {
            try
            {
                int Nparamater = 6;
                string[] name = new string[Nparamater];
                object[] values = new object[Nparamater];
                name[0] = "@TuoiNhoNhat";
                values[0] = qdDTO.TuoiNhoNhat;
                name[1] = "@TuoiLonNhat";
                values[1] = qdDTO.TuoiLonNhat;
                name[2] = "@ThoiHanThe";
                values[2] = qdDTO.ThoiHanThe;
                name[3] = "@GioiHanNam";
                values[3] = qdDTO.GioiHanNam;
                name[4] = "@MuonToiDa";
                values[4] = qdDTO.MuonToiDa;
                name[5] = "@NgayMuonGH";
                values[5] = qdDTO.NgayMuonGH;
                
                
                return connect.UpdateData("QUyDinh_UpDate", name, values, Nparamater);
            }
            catch (SqlException ex)
            {

                throw ex;
            }
            
        }
        public int GetTuoiLonNhat()
        {
            try
            {
                connect = new ConnectionData();
                DataTable dt= connect.GetData("GETTUOILONNHAT");
                return int.Parse(dt.Rows[0][0].ToString());
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int GetTuoiNhoNhat() {
            try {
                connect = new ConnectionData();
                DataTable dt= connect.GetData("GETTUOINHONHAT");
                return int.Parse(dt.Rows[0][0].ToString());
            }catch(SqlException ex){
                throw ex;
            }
        }
      
    }
}
